package kr.hkit.androidcomplete01.chapter06;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class NewMessageInflate extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.ch06_newmessageinflate);
		
		Button btn = (Button) findViewById(R.id.btnnewmsg);
		btn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				RelativeLayout rel = (RelativeLayout) View.inflate(NewMessageInflate.this, R.layout.newmessage, null);
				LinearLayout linear = (LinearLayout) findViewById(R.id.linear);
				
				if(linear.getChildCount() % 2 == 0){
					rel.setBackgroundColor(Color.GRAY);
				}else{
					rel.setBackgroundColor(Color.RED);
				}
				linear.addView(rel);
			}
		});
	}
}
